package com.yangrong.newsservice.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yangrong.newsservice.entity.TbArticleTypeEntity;
import com.yangrong.newsservice.service.TbArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yangrong.common.utils.PageUtils;
import com.yangrong.common.utils.R;


/**
 * 文章分类表
 *
 * @author yangrong
 * @email 455833224@qq.com
 * @date 2020-09-08 11:03:19
 */
@RestController
@RequestMapping("article/tbarticletype")
public class TbArticleTypeController {
    @Autowired
    private TbArticleTypeService tbArticleTypeService;

    /**
     * getAllTypeList
     */
    @RequestMapping("/getAllTypeList")
    public R getAllTypeList() {
        List<Map<String, Object>> data = tbArticleTypeService.getAllTypeList();

        return R.ok().put("typeList", data);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = tbArticleTypeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TbArticleTypeEntity tbArticleType = tbArticleTypeService.getById(id);

        return R.ok().put("tbArticleType", tbArticleType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbArticleTypeEntity tbArticleType) {
        tbArticleTypeService.save(tbArticleType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbArticleTypeEntity tbArticleType) {
        tbArticleTypeService.updateById(tbArticleType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        tbArticleTypeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
